{include app:admin.inc.header}
<!--tmpl-resource-->
{include app:admin.inc.top}


<div class="container-fluid content-body">
	<div class="main">
		<!-- left side start-->

		<section class="left-section">
			<dl id="leftNav" data-type="message">
				<dt><i class="glyphicon glyphicon-plus"></i> 信息管理</dt>
				{if in_case_array('admin/notice',$priv) || empty($priv)}
				<dd><a class="mbh" href="{url /admin/notice/index}">公告管理</a></dd>
				{/if}
				{if in_case_array('admin/information',$priv) || empty($priv)}
				<dd><a class="mbh" href="{url /admin/information/index}">资讯管理</a></dd>
				{/if}
				{if in_case_array('admin/singlepage',$priv) || empty($priv)}
				<dd><a class="mbh" href="{url /admin/singlepage/index}">单页管理</a></dd>
				{/if}
				{if in_case_array('admin/brand',$priv) || empty($priv)}
				<dd><a class="mbh" href="{url /admin/brand/index}">特约品牌</a></dd>
				{/if}
				{if in_case_array('admin/adPlace',$priv) || empty($priv)}
				<dd><a class="mbh" href="{url /admin/adPlace/index}">广告位管理</a></dd>
				{/if}
				{if in_case_array('admin/ad',$priv) || empty($priv)}
				<dd><a class="mb active" href="{url /admin/ad/index}">广告管理</a></dd>
				{/if}
			</dl>
		</section>

		<!-- left side end-->
		<!-- main content start-->
		<section class="right-section" id="right-section">
			{include admin.inc.bread}
			<h2 class="header">{$title}</h2>
			<!-- start of inner-frame -->
			<div class="inner-iframe">

				<div class="inner-container">
					<form role="form" class="content-add-form form-horizontal" id="content-add-form" autocomplete="off">
						<div class="form-group">
							<label class="col-sm-2 control-label">广告位</label>
							<div class="col-sm-4">
							<select class="form-control" id="ad-place-select"  name="data[ad_place_key]">
								{loop $adPlaces $value}
								<option value="{$value.key}" {if $item[ad_place_key]== $value[key]}selected{/if}>{$value.title}</option>
								{/loop}
							</select>
							</div>
						</div>
						<p class="help-block"></p>
						
						<div class="form-group">
							<label class="col-sm-2 control-label">广告类型</label>
							<span class="col-sm-4" style="padding-top: 3px;">图片</span>
						</div>
						<p class="help-block"></p>


						<!-- input -->
						<div class="form-group">
							<label class="col-sm-2 control-label"><span class="asterisk">*</span>标题 </label>
							<div class="col-sm-4">
								<input  dtype="" class="form-control" maxlength="50" name="data[title]" placeholder="标题" required cname="标题" value="{$item[title]}" />
								<p class="help-block"></p>
							</div>
						</div>

						<div class="form-group ad-type-image">
							<label class="col-sm-2 control-label"><span class="asterisk">*</span>图片上传</label>
							<div class="col-sm-4">
							<!--<div class="clearfix">
								<div id="image-box" class="pull-left">
								</div>
								<div class="pull-left">
									<span name="src" class="img-upload text-center" id="upload">
										<i class="glyphicon glyphicon-picture"></i>
										<span class="upload-text"><i class="glyphicon glyphicon-plus"></i> 添加图片</span>
									</span>
								</div>
							</div>-->
								<div class="fileWrap {$companyInfo[idcard_positive] != ''? 'active':''}">

									<div class="fileUpload">
										<input type="hidden" data-id="imgInput"  required cname="广告图片" name="data[content]" id="cimg_url"  value="{$companyInfo[idcard_positive]}"/>
										<input class="fileBar" id="upload" name="src" type="text" accept="image/gif, image/jpeg, image/jpg, image/png, image/bmp" />
										<div class="btn_file" >
											<!--<div class="icon_add"><i></i></div>
											<p>图片上传</p>-->
											<span class="icon_add"><i class="glyphicon glyphicon-plus">添加图片</i> </span>
										</div>
									</div>
									<div class="uploaded">
										<a class="btn_re" data-act="reUpload" href="javascript:;">删除重新上传</a>
										<p class="img" data-act="big"><img src="{$companyInfo[idcard_positive]}"/></p>
									</div>
								</div>
								<p class="help-block"></p>
							</div>
						</div>
						<!--<div class="form-group">
							<label class="col-sm-2 control-label"></label>
							<div class="col-sm-6">
								<input value="" type="hidden" required cname="广告图片" name="data[content]" id="content" />
								<p class="help-block"></p>
							</div>
						</div>-->
						<!-- input -->
						<div class="form-group ad-type-image">
							<label class="col-sm-2 control-label"><span class="asterisk">*</span>广告链接 </label>
							<div class="col-sm-6">
								<input  dtype="url" class="form-control" maxlength="255" name="data[link]" placeholder="广告链接" required cname="广告链接" value="{$item[link]}" />
								<p class="help-block"></p>
							</div>
						</div>
					
						<div class="form-group">
							<label class="col-sm-2 control-label">描述</label>
							<div class="col-sm-6">
							<textarea class="form-control" maxlength="255" name="data[summary]" placeholder="描述" cname="描述">{$item[summary]}</textarea>
							</div>
						</div>
						<p class="help-block"></p>
	
						<div class="form-group">
							<label class="col-sm-2 control-label">时间</label>
							<div>
								<label id="time-ever-label"><input type="radio" name="time-type" {if intval($item[endtime]) == 0}checked{/if}  value="1" class=""> 永久</label>
								<label id="time-set-label" ><input type="radio" name="time-type" {if intval($item[endtime]) != 0 }checked {/if} value="2"  class=""> 设定时间</label>
							</div>
						</div>	
						
						<!-- input -->
						<div class="form-group time-set">
							<label class="col-sm-2 control-label">开始时间 </label>
							<div class="col-sm-4">
							<input  dtype="" class="form-control mdate" maxlength="{maxlength}" name="data[addtime]" placeholder="开始时间" required cname="开始时间" value="{$item[addtime]}" />
							</div>
						</div>
						<p class="help-block"></p>

						<!-- input -->
						<div class="form-group time-set">
							<label class="col-sm-2 control-label">结束时间 </label>
							<div class="col-sm-4">
							<input  dtype="" class="form-control mdate" maxlength="{maxlength}" name="data[endtime]" placeholder="结束时间" required cname="结束时间" value="{$item[endtime]}" />
							</div>
						</div>
						<p class="help-block"></p>

						<div class="form-group">
							<label class="col-sm-2 control-label">打开方式</label>
							<div>
								<label><input type="radio" name="data[target]"  value="0" {if intval($item[target]) == 0}checked{/if} class="icheck"> 当前窗口</label>
								<label><input type="radio"  name="data[target]" value="1" {if $item[target] == 1}checked{/if} class="icheck"> 新窗口</label>
							</div>
						</div>

						<div class="form-group">
							<label class="col-sm-2 control-label">操作人</label>
							<div style="padding-top: 3px;">{$admin_name}</div>
						</div>


						<!--tmpl-assocfields-->
						<div class="btn-group btn-group-or">
							<a href="{if $id==''}{$do_add_url}{else}{$do_edit_url}?id={$id}{/if}" class="btnlg mb ajaxproxy"
								proxy='{"method":"post", "location":"{$index_url}"}'>提交保存</a>

						</div>
					</form><!-- content add form -->
				</div>
			</div><!-- end of inner -->
		</section>
	</div>
</div>
{include admin.inc.footer}

<!--tmpl-script-->

<!-- pagescript -->
<script type="text/javascript">
	seajs.use("admin/information_adadd",function (parameter){
        var $upload = $(".fileWrap");

        parameter.upload_url="{$upload_url}";
		parameter.image_search_url="{$image_search_url}";
		parameter.image_list_url="{$image_list_url}";
		parameter.init();		
		
		parameter.upload({
			datas:['{$item.content}'],
            onSuccess : function(data) { //上传一张图片成功回调
                //removeImage(data[data.length-2]);   ////当上传多张图片的时候，删除之前的所有图片
                var src = data[data.length-1];
                $upload.find('[data-id="imgInput"]').val(src);
                //图片显示
                $upload.find(".img img").attr("src",src);
                $upload.addClass("active");
            },
            onRemove : function(data) {
				/*$("#cimg_url").val("");*/
                $upload.find('[data-id="imgInput"]').val("");
                $upload.removeClass("active");
               // removeImage(data); //用户删除的时候，把图片也连带删除
            },
        });

        $upload.on("click",'[data-act="reUpload"]',function(){
            var $wrap=$(this).closest(".fileWrap");
            //removeImage(data); //用户删除的时候，把图片也连带删除
            $wrap.find('[data-id="imgInput"]').val("");
            $wrap.removeClass("active");
        });
        //放大图片
        $('[data-act="big"]').on('click',function(){
            var src= $(this).children("img")[0].src;
            var height = $(window).height()*0.5+'px';
            var width = $(window).width()*0.5+'px';
            var img = '<img src="'+ src+'" style="width: '+width+';height'+height+'">';
            layer.open({
                type: 1,
                title: false,
                shadeClose: true,
                content:img
            })
        });
	
		var ad_places = {{loop $adPlaces $value}{$value.id}:{$value.cate},{/loop}};	
		$(function(){
			var index = $("#ad-place-select").val();
			switchType(index);	
			$("#ad-place-select").change(function(){
				var index = $(this).val();
				switchType(index);
			});


			function switchType(index){
				var type = ad_places[index];
				if(type == 1){//文字
					$(".ad-type-image").hide();
					$(".ad-type-image textarea").attr("disabled","disabled");
					$(".ad-type-image input").attr("disabled","disabled");
					$(".ad-type-text").show();	
					$(".ad-type-text textarea").removeAttr("disabled");
					$(".ad-type-text input").removeAttr("disabled");
				}else if(type==2){//图片
					$(".ad-type-image").show();
					$(".ad-type-image textarea").removeAttr("disabled");
					$(".ad-type-image input").removeAttr("disabled");
					$(".ad-type-text").hide();
					$(".ad-type-text textarea").attr("disabled","disabled");
					$(".ad-type-text input").attr("disabled","disabled");	
				}	
			}
			
			function triggerTimeType(){
				var val = $("input[name='time-type']:checked").val();
				if(val == 1){
					$(".time-set").hide();
					$(".time-set input").attr("disabled","disabled");
				}else if(val == 2){
					$(".time-set").show();
					$(".time-set input").removeAttr("disabled");
				}		
			}
			triggerTimeType();//初始化	
		        $("input[name='time-type']").click(function(){	
				triggerTimeType();
			});	
		});
	});
</script>


<script id="assocpage" type="text/html">
<div class="text-right">
	<ul class="pagination blog-pagination">
		<li><a class="assoc-page" data-page="{[prev]}" href="javascript:void(0);">上一页</a></li> 
		{[loop pages page]}

		<li ><a class="assoc-page" data-page="{[page]}" {[if curr == page]}class="active"{[/if]} href="javascript:void(0)">{[page]}</a></li> 

		{[/loop]}
		<li><a class="assoc-page" href="javascript:void(0);" data-page="{[nexts]}">下一页</a></li> 
	</ul>	
</div>
</script>


</body>
</html>
